{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Minimum Amount of Time to Fill Cups"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #greedy #array #sorting #heap-priority-queue"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #贪心 #数组 #排序 #堆（优先队列）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: fillCups"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #装满杯子需要的最短总时长"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>现有一台饮水机，可以制备冷水、温水和热水。每秒钟，可以装满 <code>2</code> 杯 <strong>不同</strong> 类型的水或者 <code>1</code> 杯任意类型的水。</p>\n",
    "\n",
    "<p>给你一个下标从 <strong>0</strong> 开始、长度为 <code>3</code> 的整数数组 <code>amount</code> ，其中 <code>amount[0]</code>、<code>amount[1]</code> 和 <code>amount[2]</code> 分别表示需要装满冷水、温水和热水的杯子数量。返回装满所有杯子所需的 <strong>最少</strong> 秒数。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>amount = [1,4,2]\n",
    "<strong>输出：</strong>4\n",
    "<strong>解释：</strong>下面给出一种方案：\n",
    "第 1 秒：装满一杯冷水和一杯温水。\n",
    "第 2 秒：装满一杯温水和一杯热水。\n",
    "第 3 秒：装满一杯温水和一杯热水。\n",
    "第 4 秒：装满一杯温水。\n",
    "可以证明最少需要 4 秒才能装满所有杯子。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>amount = [5,4,4]\n",
    "<strong>输出：</strong>7\n",
    "<strong>解释：</strong>下面给出一种方案：\n",
    "第 1 秒：装满一杯冷水和一杯热水。\n",
    "第 2 秒：装满一杯冷水和一杯温水。\n",
    "第 3 秒：装满一杯冷水和一杯温水。\n",
    "第 4 秒：装满一杯温水和一杯热水。\n",
    "第 5 秒：装满一杯冷水和一杯热水。\n",
    "第 6 秒：装满一杯冷水和一杯温水。\n",
    "第 7 秒：装满一杯热水。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>amount = [5,0,0]\n",
    "<strong>输出：</strong>5\n",
    "<strong>解释：</strong>每秒装满一杯冷水。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>amount.length == 3</code></li>\n",
    "\t<li><code>0 &lt;= amount[i] &lt;= 100</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [minimum-amount-of-time-to-fill-cups](https://leetcode.cn/problems/minimum-amount-of-time-to-fill-cups/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [minimum-amount-of-time-to-fill-cups](https://leetcode.cn/problems/minimum-amount-of-time-to-fill-cups/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[1,4,2]', '[5,4,4]', '[5,0,0]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        # 模拟\n",
    "        amount = [-i for i in amount]\n",
    "        heapify(amount)\n",
    "        ans = 0\n",
    "        while amount[0] != 0:\n",
    "            a = heappop(amount)\n",
    "            b = heapreplace(amount, a+1)\n",
    "            heappush(amount, b+1)\n",
    "            ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        _max = max(amount)\n",
    "        _sum = sum(amount)\n",
    "        if _max >= _sum - _max:\n",
    "            return _max\n",
    "        return (_sum + 1) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0]+amount[1]<=amount[2]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0] + amount[1] <= amount[2]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        a, b, c = amount\n",
    "        if a <= c - b:\n",
    "            return c\n",
    "\n",
    "        return (a + b + c + 1) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        cnt = 0\n",
    "        while sum(amount) > 0:\n",
    "            amount.sort()\n",
    "            if amount[1] > 0 and amount[2] > 0:\n",
    "                amount[1] -= 1\n",
    "                amount[2] -= 1\n",
    "            else:\n",
    "                amount[2] -= 1\n",
    "            cnt += 1\n",
    "        return cnt\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "         return max(max(amount), math.ceil(sum(amount)/2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        mx = amount[-1]\n",
    "        mid = amount[-2]\n",
    "        mi = amount[0]\n",
    "\n",
    "        return mx + (abs(mi + mid - mx) // 2if abs(mi + mid - mx) % 2 == 0 else abs(mi + mid - mx) // 2 + 1)if mi + mid > mx else mx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        res=0\n",
    "        while 1:\n",
    "            amount.sort()\n",
    "            if amount[1]!=0:\n",
    "                amount[1]-=1\n",
    "                amount[2]-=1\n",
    "                res+=1\n",
    "            else:\n",
    "                return res+amount[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[0] + amount[1]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        a, b, c = amount\n",
    "        if a <= c - b:\n",
    "            return c\n",
    "\n",
    "        return a + b - (a - c + b) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        m = max(amount)\n",
    "        s = sum(amount)\n",
    "        if m << 1 > s:\n",
    "            return m\n",
    "        return (s + 1) >> 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        a = max(amount)\n",
    "        b = sum(amount) - a * 2\n",
    "        if a >= sum(amount) - a:\n",
    "            return a\n",
    "        else:\n",
    "            return a + b // 2 + b % 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        a = max(amount)\n",
    "        b = sum(amount) - a\n",
    "        if a >= b:\n",
    "            return a\n",
    "        else:\n",
    "            return a + (b - a) // 2 + (b - a) % 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        a, b, c = amount[0], amount[1], amount[2]\n",
    "        if c >= a + b:\n",
    "            return c\n",
    "        else:\n",
    "            for k in range(c):\n",
    "                if a != b:\n",
    "                    b -= 1\n",
    "                else:\n",
    "                    a -= 1\n",
    "            return c + max(a, b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        return max((sum(amount)+1)//2,max(amount))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2]>amount[1]+amount[0]:\n",
    "            return amount[2]\n",
    "        return (sum(amount)+1)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        count = 0\n",
    "        while sum(amount):\n",
    "            amount.sort()\n",
    "            count = count + 1\n",
    "            amount[2] = amount[2]-1\n",
    "            amount[1] = max(0,amount[1]-1)\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        stack = [-num for num in amount if num]\n",
    "        ans = 0\n",
    "        heapify(stack)\n",
    "        while len(stack) >= 2:\n",
    "            a, b = heappop(stack), heappop(stack)\n",
    "            ans += 1\n",
    "            a += 1\n",
    "            b += 1\n",
    "            if a:\n",
    "                heappush(stack, a)\n",
    "            if b:\n",
    "                heappush(stack, b)\n",
    "        return ans - sum(stack)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        max_val = max(amount)\n",
    "        su = sum(amount)\n",
    "        if max_val <= su - max_val:\n",
    "            return (su - 1) // 2 + 1\n",
    "        return max_val"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while sum(amount):\n",
    "            amount.sort()\n",
    "            ans += 1\n",
    "            amount[2] -= 1\n",
    "            amount[1] = max(0, amount[1] - 1)\n",
    "        return ans\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[1] + amount[0]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        mins = min(amount)\n",
    "        maxs = max(amount)\n",
    "        mid = sum(amount)-mins-maxs\n",
    "        if not mins:\n",
    "            return min(maxs, mid) + maxs-mid\n",
    "        return self.fillCups([mins-1, mid, maxs-1]) + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        return max(amount[0],amount[1],amount[2],((sum(amount)+1) // 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        # 贪心，每次都是最大和最小\n",
    "        cnt = 0\n",
    "        while amount.count(0) != 3:\n",
    "            amount.sort()\n",
    "            cnt += 1\n",
    "            amount[-1] -= 1\n",
    "            if amount[0]:\n",
    "                amount[0] -= 1\n",
    "            else:\n",
    "                amount[1] = max(0, amount[1]-1)\n",
    "        \n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[1] + amount[0]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        return max((sum(amount)+1)//2,max(amount))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, nums: List[int]) -> int:\n",
    "        for ans in range(151):\n",
    "            if not sum(nums): return ans\n",
    "            nums = sorted(nums)\n",
    "            nums[2] -= 1\n",
    "            if nums[1]: nums[1] -= 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        count = 0\n",
    "        amount.sort()\n",
    "        if amount[0] + amount[1] <= amount[2]:\n",
    "            return amount[2]\n",
    "        else:\n",
    "            return (sum(amount)+1)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        return max((sum(amount) + 1) // 2, max(amount))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[0] + amount[1]:\n",
    "            return amount[2]\n",
    "        else:\n",
    "            return (sum(amount) + 1) // 2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0] + amount[1] <= amount[2]:\n",
    "            return amount[2]\n",
    "        else:\n",
    "            n = amount[0] + amount[2] - amount[1]\n",
    "            if n % 2:\n",
    "                return (n+1) // 2 + amount[1]\n",
    "            else:\n",
    "                return n // 2 + amount[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount) -> int:\n",
    "        ans=0\n",
    "        amount.sort()\n",
    "        while min(amount)!=0:\n",
    "            amount[2]=amount[2]-1\n",
    "            amount[1]=amount[1]-1\n",
    "            ans=ans+1\n",
    "            amount.sort()\n",
    "        ans= ans + max(amount)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        ans = 0\n",
    "        while amount[1] != 0:\n",
    "            \n",
    "            amount[2] -= 1\n",
    "            amount[1] -= 1\n",
    "            ans += 1\n",
    "            amount.sort()\n",
    "        ans += amount[2]\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while True:\n",
    "            amount.sort()\n",
    "            if amount[-1] == 0:\n",
    "                break\n",
    "            amount[-1] -= 1\n",
    "            if amount[-2] != 0:\n",
    "                amount[-2] -= 1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        res = 0\n",
    "        amount.sort()\n",
    "        while amount[0] != 0 and amount[1] != 0:\n",
    "            amount[2] -= 1\n",
    "            amount[1] -= 1\n",
    "            amount.sort()\n",
    "            res += 1\n",
    "        return res + amount[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        max1 = max(amount)\n",
    "        sum1 = sum(amount)\n",
    "        if max1 >= sum1 / 2:\n",
    "            return max1\n",
    "        return sum1%2+sum1//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount) -> int:\n",
    "        res=0\n",
    "        h = []\n",
    "        for m in amount:\n",
    "            if m!=0:\n",
    "                heappush(h,-m)\n",
    "        while len(h)>1:\n",
    "            m,n=heappop(h),heappop(h)\n",
    "            res+=1\n",
    "            if m+1!=0:\n",
    "                heappush(h,m+1)\n",
    "            if n+1!=0:\n",
    "                heappush(h,n+1)\n",
    "        \n",
    "        if len(h)==1:\n",
    "            res-=h[0]\n",
    "        \n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        result = 0\n",
    "        while max(amount)!=0:\n",
    "            amount.sort(reverse=True)\n",
    "            if amount[0]!=0 and amount[1]!=0:\n",
    "                result+=1\n",
    "                amount[0]-=1\n",
    "                amount[1]-=1\n",
    "            elif amount[1]==0:\n",
    "                result+=amount[0]\n",
    "                amount[0]=0\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:        \n",
    "        count=0\n",
    "        amount.sort()\n",
    "        while amount[-1]>0:            \n",
    "            count+=1\n",
    "            amount[-2]-=1\n",
    "            amount[-1]-=1        \n",
    "            amount.sort()\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        s = sorted(amount, reverse=True)\n",
    "        # while s[0] != 0:\n",
    "        #     if s[1] != 0: \n",
    "        #         s[0] -= 1\n",
    "        #         s[1] -= 1\n",
    "        #         ans += 1\n",
    "        #     else:\n",
    "        #         ans += s[0]\n",
    "        #         s[0] = 0\n",
    "        #     s = sorted(s, reverse=True)\n",
    "\n",
    "        # return ans\n",
    "\n",
    "        if s[1] + s[2] <= s[0]:\n",
    "            return s[0]\n",
    "        else:\n",
    "            return s[0] + (s[1] + s[2] - s[0] + 1) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0]+amount[1]<=amount[2]:\n",
    "            return amount[2]\n",
    "        return sum(amount)//2 if sum(amount)%2==0 else (sum(amount)//2+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "      if 2*max(amount)>=sum(amount):\n",
    "        return max(amount)\n",
    "      else:\n",
    "        return (sum(amount)+1)//2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[1] + amount[0]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        return max(*amount, sum(amount, 1) >> 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[1] + amount[0]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        a = sum(amount) - max(amount)\n",
    "        b = max(amount)\n",
    "        return b if a < b else b + (a-b+1)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        maxp = max (amount)\n",
    "        sump = sum (amount)\n",
    "        if(maxp > sump - maxp):\n",
    "            return maxp\n",
    "        return (sump + 1)//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0] + amount[1] <= amount[2]:\n",
    "            return amount[2]\n",
    "        else:\n",
    "            return math.ceil(sum(amount)/2)\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        # 涉及最小操作次数 -- 结果是和=0且最大-最小=0\n",
    "        count = 0\n",
    "        while(sum(amount)!=0):\n",
    "            amount.sort()\n",
    "            if amount[0] != 0:\n",
    "                amount[0] -= 1\n",
    "                amount[-1] -= 1\n",
    "            elif amount[1] != 0:\n",
    "                amount[1] -= 1\n",
    "                amount[-1] -= 1\n",
    "            else:\n",
    "                amount[-1] -= 1\n",
    "\n",
    "            count += 1\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while sum(amount):\n",
    "            amount.sort()\n",
    "            ans += 1\n",
    "            amount[2] -= 1\n",
    "            amount[1] = max(0, amount[1] - 1)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0]+amount[1]<=amount[-1]:\n",
    "            return amount[-1]\n",
    "        else:\n",
    "            return (sum(amount)+1)//2\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        # 模拟\n",
    "        amount = [-i for i in amount]\n",
    "        heapify(amount)\n",
    "        ans = 0\n",
    "        while amount[0] != 0:\n",
    "            a = heappop(amount)\n",
    "            b = heapreplace(amount, a+1)\n",
    "            heappush(amount, b+1)\n",
    "            ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        max1 = max(amount)\n",
    "        sum1 = sum(amount)\n",
    "        if max1 >= sum1 / 2:\n",
    "            return max1\n",
    "        return sum1%2+sum1//2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        s = sorted(amount, reverse=True)\n",
    "        while s[0] != 0:\n",
    "            if s[1] != 0: \n",
    "                s[0] -= 1\n",
    "                s[1] -= 1\n",
    "                ans += 1\n",
    "            else:\n",
    "                ans += s[0]\n",
    "                s[0] = 0\n",
    "            s = sorted(s, reverse=True)\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        最大值 = max(amount)\n",
    "        和 = sum(amount)\n",
    "        if 和 > 最大值*2:\n",
    "            return 最大值 + (和-最大值*2+1)//2\n",
    "        return 最大值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        r = 0\n",
    "        while sum(amount) > 0:\n",
    "            amount.sort(reverse=True)\n",
    "            amount[0] = max(0, amount[0] - 1)\n",
    "            amount[1] = max(0, amount[1] - 1)\n",
    "            r += 1\n",
    "        return r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[-1] > sum(amount[:-1]):\n",
    "            return amount[-1]\n",
    "        else:\n",
    "            return (sum(amount) + 1) // 2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        result = 0\n",
    "        amount.sort(reverse=True)\n",
    "        while amount[0]!=0:\n",
    "            \n",
    "            if amount[0]!=0 and amount[1]!=0:\n",
    "                result+=1\n",
    "                amount[0]-=1\n",
    "                amount[1]-=1\n",
    "            elif amount[1]==0:\n",
    "                result+=amount[0]\n",
    "                amount[0]=0\n",
    "            amount.sort(reverse=True)\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        res=0\n",
    "        amount.sort(reverse=True)\n",
    "        while amount[0]>0 or amount[1]>0 or amount[2]>0:\n",
    "            if amount[0]>0 and amount[1]>0:\n",
    "                amount[0]-=1\n",
    "                amount[1]-=1\n",
    "                amount.sort(reverse=True)\n",
    "            elif amount[0]>0 and amount[1]==0:\n",
    "                amount[0]-=1\n",
    "            else:\n",
    "                break\n",
    "            res+=1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        time=0\n",
    "        while sum(amount):\n",
    "            amount.sort()\n",
    "            amount[2]-=1\n",
    "            amount[1]=max(0,amount[1]-1)\n",
    "            time+=1\n",
    "        return time\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        n = 0\n",
    "        while True:\n",
    "            if sum(amount) == 0:\n",
    "                return n\n",
    "            amount.sort()\n",
    "            amount[-1] -= 1\n",
    "            n += 1\n",
    "            if amount[-2] > 0:\n",
    "                amount[-2] -= 1\n",
    "        return n\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        cnt = 0\n",
    "        amount.sort()\n",
    "        while True:\n",
    "            amount.sort()\n",
    "            if amount[1] == 0:\n",
    "                cnt += amount[2]\n",
    "                break\n",
    "            else:\n",
    "                cnt += 1\n",
    "                amount[2] -= 1\n",
    "                amount[1] -= 1\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        # 模拟\n",
    "        amount = [-i for i in amount]\n",
    "        heapify(amount)\n",
    "        ans = 0\n",
    "        while amount[0] != 0:\n",
    "            a = heappop(amount)\n",
    "            b = heapreplace(amount, a+1)\n",
    "            heappush(amount, b+1)\n",
    "            ans += 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while sum(amount):\n",
    "            amount.sort()\n",
    "            amount[2] -= 1\n",
    "            amount[1] = max(0, amount[1] - 1)\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        x, y, z = amount\n",
    "        if x + y <= z:\n",
    "            return z\n",
    "        return z + (x + y - z) // 2 + (x + y - z) % 2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        hot = amount[0]\n",
    "        median=amount[1]\n",
    "        cold=amount[2]\n",
    "        day=0\n",
    "        while True:\n",
    "            min_value=99999\n",
    "            for x in amount:\n",
    "                if x>0:\n",
    "                    min_value=min(min_value,x);\n",
    "            if max(amount)==0:\n",
    "                break;\n",
    "            if amount[0]==max(amount) and amount[0]>0:\n",
    "                amount[0]-=1\n",
    "                if amount[1]==min_value and amount[1]>0:\n",
    "                    amount[1]-=1\n",
    "                elif amount[2]==min_value and amount[2]>0:\n",
    "                    amount[2]-=1\n",
    "            elif amount[1]==max(amount) and amount[1]>0:\n",
    "                amount[1]-=1\n",
    "                if amount[0]==min_value and amount[0]>0:\n",
    "                    amount[0]-=1\n",
    "                elif amount[2]==min_value and amount[2]>0:\n",
    "                    amount[2]-=1\n",
    "            elif amount[2]==max(amount) and amount[2]>0:\n",
    "                amount[2]-=1\n",
    "                if amount[0]==min_value and amount[0]>0:\n",
    "                    amount[0]-=1\n",
    "                elif amount[1]==min_value and amount[1]>0:\n",
    "                    amount[1]-=1\n",
    "            print(amount)\n",
    "            day+=1\n",
    "        return day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        maxn=max(amount)\n",
    "        sumn=sum(amount)\n",
    "        res=sumn-maxn\n",
    "        if res>=maxn:\n",
    "            return (sumn+1)//2\n",
    "        else:\n",
    "            alone=maxn-res\n",
    "            return res+alone"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        mx = max(amount)\n",
    "        temp = mx\n",
    "        i = amount.index(mx)\n",
    "        k1 = -1\n",
    "        k2 = -1\n",
    "        for j in range(3):\n",
    "            if j == i:\n",
    "                continue\n",
    "            if k1 == -1:\n",
    "                k1 = amount[j] \n",
    "            else:\n",
    "                k2 = amount[j]\n",
    "        temp -= abs(k1-k2)\n",
    "        k1 = k2 = min(k1,k2)\n",
    "        if temp >= k1 + k2:\n",
    "            return mx\n",
    "        k1 -= temp // 2\n",
    "        k2 -= temp // 2\n",
    "        if temp % 2 != 0:\n",
    "            k1 -= 1\n",
    "        return mx + k2\n",
    "               "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[0] + amount[1] <= amount[2]:\n",
    "            return amount[2]\n",
    "        else:\n",
    "            return (sum(amount)+1) // 2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[1] + amount[0]:\n",
    "            return amount[2]\n",
    "        return (sum(amount) + 1) // 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        a=[-i for i in amount]\n",
    "        heapq.heapify(a)\n",
    "        num=0\n",
    "        while True:\n",
    "            x=heapq.heappop(a)\n",
    "            if x==0:\n",
    "                return num\n",
    "            y=heapq.heappop(a)\n",
    "            if y==0:\n",
    "                return num-x\n",
    "            heapq.heappush(a,x+1)\n",
    "            heapq.heappush(a,y+1)\n",
    "            num+=1\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# https://leetcode.cn/problems/minimum-amount-of-time-to-fill-cups/\n",
    "from typing import List\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans, size = 0, sum([1 for item in amount if item > 0])\n",
    "        while size > 1:\n",
    "            amount.sort(reverse=True)\n",
    "            if amount[0] > 0:\n",
    "                amount[0] -= 1\n",
    "            if amount[1] > 0:\n",
    "                amount[1] -= 1\n",
    "            size = sum([1 for item in amount if item > 0])\n",
    "            ans += 1\n",
    "        amount.sort(reverse=True)\n",
    "        ans += amount[0]\n",
    "        return ans\n",
    "\n",
    "\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    s = Solution()\n",
    "    for testcase in [\n",
    "        [0, 0, 0],\n",
    "        [1, 4, 2],\n",
    "        [5, 4, 4],\n",
    "        [5, 0, 0],\n",
    "    ]:\n",
    "        ret = s.fillCups(testcase)\n",
    "        print(\"testcase={}, ret={}\".format(testcase, ret))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        count = 0\n",
    "        while sum(amount):\n",
    "            amount.sort()\n",
    "            count += 1\n",
    "            amount[2] -= 1\n",
    "            if amount[1] != 0:\n",
    "                amount[1] -= 1\n",
    "        return count\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        ans = 0\n",
    "        while sum(amount) > 0:\n",
    "            amount.sort()\n",
    "            if amount[0] == 0 or amount[0]+amount[1] <= amount[2]:\n",
    "                ans += amount[2]\n",
    "                break\n",
    "            elif amount[1] > amount[0]:\n",
    "                t = amount[1]-amount[0]\n",
    "                amount[1] -= t\n",
    "                amount[2] -= t\n",
    "                ans += t\n",
    "            elif amount[1] == amount[0] and (amount[2]-amount[0])//2:\n",
    "                t = (amount[2]-amount[0])//2\n",
    "                amount[0] -= t\n",
    "                amount[1] -= t\n",
    "                amount[2] -= 2*t\n",
    "                ans += 2*t\n",
    "            elif amount[0] > 1:\n",
    "                t = amount[0]//2\n",
    "                ans += 3*t\n",
    "                amount[0] -= t*2\n",
    "                amount[1] -= t*2\n",
    "                amount[2] -= t*2\n",
    "            else:\n",
    "                ans += 1\n",
    "                amount[0] -= 1\n",
    "                amount[2] -= 1\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def fillCups(self, amount: List[int]) -> int:\n",
    "        amount.sort()\n",
    "        if amount[2] > amount[1] + amount[0]:\n",
    "            return amount[2]\n",
    "        else:\n",
    "            return math.ceil(sum(amount) / 2)\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
